/*
 * 寰俊鍏紬骞冲彴(JAVA) SDK
 *
 * Copyright (c) 2014, Ansitech Network Technology Co.,Ltd All rights reserved.
 * 
 * http://www.weixin4j.org/sdk/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.wuye.weixin.http;

/**
 * 微信企业号对象
 *
 * <p>每一次请求即对应一个<tt>HttpClient</tt>，
 * 每次登陆产生一个<tt>OAuth</tt>用户连接,使用<tt>OAuthToken</tt>
 * 可以不用重复向微信平台发送登陆请求，在没有过期时间内，可继续请求。</p>
 *
 */
public class QyOAuth implements java.io.Serializable {

    private String corpID = "";
    private String corpSecret;

    /**
     * 创建微信公众号实例
     *
     * @param appId 第三方用户唯一凭证
     * @param secret 第三方用户唯一凭证密钥
     */
    public QyOAuth(String appId, String secret) {
        setCorpID(appId);
        setCorpSecret(secret);
    }

    public String getCorpID() {
        return corpID;
    }

    public void setCorpID(String corpID) {
        this.corpID = corpID = null != corpID ? corpID : "";
    }

    public String getCorpSecret() {
        return corpSecret;
    }

    public void setCorpSecret(String corpSecret) {
        this.corpSecret = corpSecret = null != corpSecret ? corpSecret : "";
    }

    @Override
    public boolean equals(Object o) {
        if (o == null) {
            return false;
        }
        if (!(o instanceof QyOAuth)) {
            return false;
        }

        QyOAuth oAuth = (QyOAuth) o;

        if (oAuth.getCorpID() == null || !this.corpID.equals(oAuth.getCorpID())) {
            return false;
        }
        if (oAuth.getCorpSecret() == null || !this.corpSecret.equals(oAuth.getCorpSecret())) {
            return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        int result = this.corpID != null ? this.corpID.hashCode() : 0;
        result = 31 * result + (this.corpSecret != null ? this.corpSecret.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "{corpID='" + this.corpID + "',corpSecret='" + this.corpSecret + "'}";
    }
}
